package com.otv.core;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.otv.model.Role;

public class ConvertorUtility {

	public static List<String> convert(List list, String fieldName) {
		List<String> ret = new ArrayList<String>();
		for (Object objectCpt : list) {
			System.out.println("to made it");     
			Class<? extends Object> class1 = objectCpt.getClass();
			Field declaredField;
			try {
				declaredField = class1.getDeclaredField(fieldName);
			} catch (SecurityException e) {
				e.printStackTrace();
				throw new RuntimeException("FATAL_ERROR " + e);
				

			} catch (NoSuchFieldException e) {
				e.printStackTrace();
				throw new RuntimeException("FATAL_ERROR " + e+" class="+class1);
			}
			Object value;
			try {
				declaredField.setAccessible(true);
				value = declaredField.get(objectCpt);  
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
				throw new RuntimeException("FATAL_ERROR " +  e+" class="+class1);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
				throw new RuntimeException("FATAL_ERROR " + e+" class="+class1);
			}
			ret.add(value.toString());
			System.out.println("check");
		}
		return ret;
	}

}
